﻿@model IEnumerable<Nutrapp.DBAL.Ingredient>


@{
    ViewBag.Title = "Index";
}

<div class="list_category" style="width: 20%; float: left; margin-bottom: 10px;">
    <ul style="list-style: none">
        <li style="list-style: none">
            <h2>Category</h2>

            @{
                if (@Session["deleteError"] != null)
                {
                <p style="color: red">
                    @Session["deleteError"].ToString()
                </p>
                    Session["deleteError"] = "";
                }
            }


        </li>
        <p>@Html.ActionLink("Create New", "Create", "Category")</p>
        @{
             
            List<Nutrapp.DBAL.Ingredient> itemList = Model.GroupBy(i => i.Ingredients_Category.ID).Select(g => g.First()).ToList();

            foreach (var item in itemList)
            {
            <li>
                <a href="~/Ingredients/Index?id=@item.Ingredients_Category.ID">@item.Ingredients_Category.Name</a>

            </li>
            }
        }
    </ul>

</div>



<div class="ingredients" style="width: 40%; float: left; margin-top: 0px">
    <div class="spa12">
        @if (Request.QueryString["id"] == null)
        {
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th style="width: 50%">Ingredient</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <h2>Ingredients List</h2>
                    <p>
                        @Html.ActionLink("Create New", "Create")
                    </p>                    
                </tbody>
            </table>
        }
        else
        {   
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>Ingredient
                        </th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <h2>Ingredients List</h2>
                    <p>
                        @Html.ActionLink("Create New", "Create")
                    </p>
                    @foreach (var item in Model)
                    {
                        if (item.Category == int.Parse(Request.QueryString["id"]))
                        {               
                        
                        
                        <tr>
                            <td>
                                @Html.DisplayFor(modelItem => item.Name)
                            </td>
                            <td>
                                @Html.ActionLink("Edit", "Edit", new { id = item.ID }) |                            
                            @Html.ActionLink("Delete", "Delete", new { id = item.ID })
                            </td>
                        </tr>
                        }
                    }
                </tbody>
            </table>
        }
    </div>
</div>

